﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CHPM.PL.DesktopUI.Code.Validation;
using CHPM.PL.DesktopUI.Interfaces;
using CHPM.PL.DesktopUI.ServiceReference1;
using CHPM.PL.DesktopUI.Code.Common;
using System.Windows.Forms;
using CHPM.IC.ServiceLocator;

namespace CHPM.PL.DesktopUI.Presenters
{
    public class NewPatientPresenter : BasePresenter
    {
        private INewPatient _newPatientView;
        private IMainService _mainService;

        public NewPatientPresenter(IServiceLocator serviceLocator, IPatientPersonalData newPatientView)
            : base(serviceLocator)
        {
            _newPatientView = (INewPatient)newPatientView;

            _mainService = serviceLocator.Resolve<IMainService>();
            _newPatientView.OnUserSaving += new EventHandler<ConsoleCancelEventArgs>(PatientSender);
        }


        public void PatientSender(Object sender, ConsoleCancelEventArgs args)
        {
            PATIENT newPatient = new PATIENT();

            newPatient.ADRESS = _newPatientView.Address;
            newPatient.FULLNAME = _newPatientView.FullName;
            newPatient.CARD = _newPatientView.Card;
            newPatient.PHONE = _newPatientView.Phone;
            newPatient.BIRTHDATE = _newPatientView.Birthday;
            newPatient.ENTER_DATE = _newPatientView.EnterDate;
            newPatient.INVAL = _newPatientView.Invalid;
            newPatient.ID_TREATMENT_COURSE = _newPatientView.TreatmentCourse;
            newPatient.AMBULATORY = _newPatientView.Ambulatory;
            newPatient.GENDER = _newPatientView.Sex;
            newPatient.IS_CHORNOBUL = _newPatientView.Chornobyl;
            newPatient.IS_CITIZEN = _newPatientView.Citizen;
            newPatient.IS_SANATORY = _newPatientView.Sanatoriy;

            _mainService.InsertPatient(newPatient);
        }

        public void PresentNewPatient(Control container)
        {
            this.ClearControls(container);
            container.Controls.Add(_newPatientView.AsControl);
            container.Controls[container.Controls.Count - 1].Dock = DockStyle.Fill;
        }
    }
}
